package com.lhl.mongodb;

import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCursor;
import org.bson.Document;

public class Main {
    public static void main(String[] args) throws Exception {
        final String DBName = "textworld";
        final String ServerAddress = "127.0.0.1";
        final int PORT = 20222;

        MongoHelper mongoHelper = new MongoHelper(ServerAddress,PORT,DBName);

        MongoDao aeraDao = mongoHelper.getDao("aera");
//        aeraDao.insert("{_id:'a',a:2,b:3,c:4}");
//        aeraDao.insert("{_id:'b',a:2,b:3,c:4}");
//        aeraDao.insert("{_id:'c',a:2,b:3,c:4}");
//
//        aeraDao.delete("{_id:'a',a:2,b:3,c:4}");
//
//        aeraDao.updateOne("{_id:'a'}","{a:8}");
//        aeraDao.updateMany("{}","{a:8}");

        FindIterable<Document> doc = aeraDao.find("{_id:'a'}");
        doc = aeraDao.find("{}");
        MongoCursor<Document> iterator = doc.iterator();
        while(iterator.hasNext()){
            Document document1 = iterator.next();
            System.out.println(document1.toJson());
        }

    }

}